from .base import Base


class Post(Base):
    __DELETE_URL = "/admin/goods/delete"
    __POST = "post"
    __ADD_URL = "/admin/goods/create"
    __CORRECT_URL = "/admin/goods/update"

    def delete(self, goodsId, goodsSn=None, name=None):
        url = self.url + self.__DELETE_URL
        json = {
            "id": goodsId,
            "goodsSn": goodsSn,
            "name": name
        }
        return self.send(self.__POST, url, headers=self.headers, verify=False, json=json)

    def add(self, goodsSn=None, name=None):
        url = self.url + self.__ADD_URL
        json = {
          "goods": {
            "picUrl": "",
            "gallery": [],
            "isHot": "false",
            "isNew": "true",
            "isOnSale": "true",
            "goodsSn": goodsSn,
            "name": name
          },
          "specifications": [
            {
              "specification": "规格",
              "value": "标准",
              "picUrl": ""
            }
          ],
          "products": [
            {
              "id": 0,
              "specifications": [
                "标准"
              ],
              "price": 0,
              "number": 0,
              "url": ""
            }
          ],
          "attributes": []
        }
        return self.send(self.__POST, url, headers=self.headers, verify=False, json=json)

    def correct(self, goodsId, goodsSn=None, name=None):
        url = self.url + self.__CORRECT_URL
        json = {
          "goods": {
            "id": goodsId,
            "goodsSn": goodsSn,
            "name": name,
            "categoryId": 0,
            "brandId": "null",
            "gallery": [],
            "keywords": "null",
            "brief": "",
            "isOnSale": "true",
            "sortOrder": 100,
            "picUrl": "",
            "isNew": "true",
            "isHot": "false",
            "unit": "’件‘",
            "counterPrice": 0,
            "retailPrice": 0,
            "addTime": "2024-09-23 09:08:04",
            "updateTime": "2024-09-23 09:08:04",
            "deleted": "false"
          },
          "specifications": [
            {
              "id": 284728,
              "goodsId": 1465582,
              "specification": "规格",
              "value": "标准",
              "picUrl": "",
              "addTime": "2024-09-23 09:08:04",
              "updateTime": "2024-09-23 09:08:04",
              "deleted": "false"
            }
          ],
          "products": [
            {
              "id": 284718,
              "goodsId": 1465582,
              "specifications": [
                "标准"
              ],
              "price": 0,
              "number": 0,
              "url": "",
              "addTime": "2024-09-23 09:08:04",
              "updateTime": "2024-09-23 09:08:04",
              "deleted": "false"
            }
          ],
          "attributes": []
        }
        return self.send(self.__POST, url, headers=self.headers, verify=False, json=json)
